package cn.nuc.controller.sensorfire.before;

import cn.nuc.controller.login.LoginController;
import cn.nuc.controller.warning.WaringController;
import cn.nuc.pojo.sensorfire.Sensor;
import cn.nuc.service.sensorfire.ISensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
public class SensorController2 {
    @Autowired
    private ISensorService sensorService;
    @GetMapping("/sensor")
    public String sensor(Model model , HttpServletRequest request){
        LoginController.url = "sensor";
        List<Sensor> sensorList = sensorService.list();
        String pwdMsg = (String) request.getSession().getAttribute("pwdMsg");
        request.getSession().removeAttribute("pwdMsg");
        if(sensorList != null){
            model.addAttribute("sensorList" , sensorList);
            model.addAttribute("pwdMsg" , pwdMsg);
            return "sensor";
        }
        return "fail";
    }
    @RequestMapping("/local/{url}")
    public String localRefresh(Model model , @PathVariable String url) {
        Object sensor = LoginController.session.getAttribute("sensor");
        System.out.println(sensor);
        model.addAttribute("sensor" , sensor);
        return url +" :: warn2";
    }
    @RequestMapping("/local2/{url}")
    public String  localRefresh2(Model model , @PathVariable String url) {
        LoginController.session.setAttribute("sensor" , '无');
        model.addAttribute("sensor" , '无');
       return url +" :: warn2";
    }

//    @PostMapping("/sensor")
//    public String sensor(Model model , String search , HttpServletRequest request){
//        QueryWrapper queryWrapper = null;
//        if(search != null){
//            queryWrapper = new QueryWrapper<Sensor>().like("location" , search).or().eq("status" , search);
//        }
//        List<Sensor> sensorList = sensorService.list(queryWrapper);
//        String pwdMsg = (String) request.getSession().getAttribute("pwdMsg");
//        request.getSession().removeAttribute("pwdMsg");
//        if(sensorList != null){
//            model.addAttribute("sensorList" , sensorList);
//            model.addAttribute("pwdMsg" , pwdMsg);
//            return "sensor";
//        }
//        return "fail";
//    }
}
